package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.AnnouncementComment;
import com.jianyun.jyzs.widget.CicleImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by mlli on 2017/11/20.
 */

public class CommentAdapter extends RecyclerView.Adapter {


    private Context context;
    private List<AnnouncementComment.AnnComment> list;

    public CommentAdapter(Context context, List<AnnouncementComment.AnnComment> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<AnnouncementComment.AnnComment> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_comment, parent, false);
        return new MHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final MHolder mHolder = (MHolder) holder;
        AnnouncementComment.AnnComment comment = list.get(position);
        mHolder.tvComment.setText(comment.getCommentContent());
        String employeeID = comment.getCommentEmployeeID();
        Picasso.with(context).load(R.drawable.rc_default_portrait).into(mHolder.portrait);

        mHolder.tvCommentName.setText(comment.getCommentName());
        mHolder.tvCommentTime.setText(comment.getCommentTime().substring(0, 10));
        mHolder.tvComment.setText(comment.getCommentContent());


    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.portrait)
        CicleImageView portrait;
        @BindView(R.id.tv_comment_name)
        TextView tvCommentName;
        @BindView(R.id.tv_comment)
        TextView tvComment;
        @BindView(R.id.tv_comment_time)
        TextView tvCommentTime;

        public MHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
